package com.gmail.dmitryustimov.ms.factory.mod.java8_one_arg;


public class Client {

    Factory<ProductA> factoryA;
    Factory<ProductB> factoryB;
    ProductA productA;
    ProductB productB;

    public Client() {
        factoryA = new Factory<ProductA>();
        factoryB = new Factory<ProductB>();
    }

    void make(int productFamilyId) {
        if (productFamilyId == Constants.PRODUCT_FAMILY_1_ID) {

            System.out.println("1-1: " + factoryA.create(createProductA1));
            System.out.println("1-2: " + factoryB.create(createProductB1));
        }
        else if (productFamilyId == Constants.PRODUCT_FAMILY_2_ID) {
            System.out.println("2-1: " + factoryA.create(createProductA2));
            System.out.println("2-2: " + factoryB.create(createProductB2));
        }
    }

    Creator<ProductA> createProductA1 = () -> {
        return new ProductA1();
    };

    Creator<ProductB> createProductB1 = () -> {
        return new ProductB1();
    };

    Creator<ProductA> createProductA2 = () -> {
        return new ProductA2();
    };

    Creator<ProductB> createProductB2 = () -> {
        return new ProductB2();
    };
}
